// const shopId = wx.getStorageSync('shopId');
//调用api的时候，如果是请求的数据，不需要关联shop_id则把shop_id字段传为空置{shop_id:''}
const apiUrl = require('./NetTool.js');
const appInfo = require ('../appInfo')
var app = getApp();
var token;
const apis = {
   /**
   * 生成订单后的支付
   * obj  下单后生成的支付信息
   * fn 成功后的回调
   * fn2 失败后的回调（支付失败后订单状态会转为待支付）
   */
 
		wxPayment: function (obj, fn, fn2) {
			console.log('wxPayment')
		  var data = obj;
		  var that = this; 
		  uni.getProvider({
		  	service: 'oauth',
		  	success:res =>{
		  		console.log('getProvider',res)
		  	 
		  	}	
		  })
		  uni.requestPayment({
			provider: 'wxpay',
			orderInfo:{
				'timeStamp': data.timeStamp,
				'nonceStr': data.nonceStr,
				'package': data.packages,
				'signType': data.signType,
				'paySign': data.paySign,
				'level_id': data.level_id,
			},

		    'success': function (res) {
		      // that.clearGoodsCart();
		      wx.showToast({
		        title: '支付成功',
		      })
		      typeof fn == "function" && fn(res)
		    },
		    'fail': function (res) {
				console.log(res)
		      wx.showToast({
		        title: '支付失败',
		      })
		      typeof fn2 == "function" && fn2(res)
		    }
		  })
		},
		/**
		 * 
		 * @param {订单id} id 
		 * @param {订单金额} amount 
		 * @param {用户的openid} open_id 
		 * @param {支付成功的回调} fn 
		 * @param {支付失败回调} fn2
		 */
		buyWeChatLitOnline: function (id, amount, open_id, sku_name, fn, fn2) {
		  var that = this;
		  console.log('buyWeChatLitOnline')
		  apiUrl.getAjaxUrlValue('capi/wcoa/order.do', {
		    open_id: open_id,
		    server_ip: "118.26.175.56",
		    amount: amount,
		    wxNotifyUrl: appInfo.wxNotifyUrl,
		    update_api: 1,
		    order_id: id,
		    sku_name: sku_name
		  }, (res) => {
			  console.log('getAjaxUrlValue')
			console.log('回调信息',res)
		    that.wxPayment(res.rows, res => {
				console.log(res)
		      fn(res)
		    }, fn2)
		  })
		
		},
		setDefaultTeam: function (teamMemberList, defaultTeamId,fn) {
		  //  
		  let ids = []
		  teamMemberList.forEach((e) => {
		    ids.push(e.id)
		  })
		  apiUrl.getAjaxUrlValueBackground('capi/V2/theasklist/flyTeamMember/update', {
		    id: ids.join(),
		    is_default: 0
		  }, function (res) {
		    apiUrl.getAjaxUrlValueBackground('capi/V2/theasklist/flyTeamMember/update', {
		      id: defaultTeamId,
		      is_default: 1
		    }, function (res) {
		      //  
		      typeof fn == "function" && fn();
		
		    })
		  })
		  // apiUr.getAjaxUrlValueBackground('capi/message/sendMsg', pData, function (res) { 
		  //    ;
		  // })
		}
		,
		
		/***
		 * 健全用户信息时调用（或者修改用户信息时调用）
		 * 用户信息的获取
		 * fn  成功后的回调(false  获取失败)
		 */
		memberUserGetInfoById: function (data, fn) {
		  //  
		  wx.getUserInfo({
		    success: function (res) {
		      var data = {
		        avatar: res.userInfo.avatarUr,
		        gender: res.userInfo.gender,
		        nick_name: res.userInfo.nickName
		      }
		      typeof fn == "function" && fn(data)
		    },
		    fail: function (res) {
		      typeof fn == "function" && fn(false)
		      wx.showToast({
		        title: "获取用户信息失败",
		        icon: 'success',
		        image: "/images/info.png",
		        duration: 2000
		      })
		    }
		  })
		},
 

}
module.exports = apis;